#include "totalcontrol.h"

TotalControl::TotalControl(QGraphicsScene *m_scene)
{
    scene = m_scene;//完成赋值
    for(int i=0;i<20;i++){
        smallEnemy = new SmallEnemy(scene);
        smallEnemy->setPos(QPointF(-40,-40));
        SmallEnemyList.append(smallEnemy);
    }
    for(int i=0;i<10;i++){
        followEnemy = new FollowSmallEnemy(scene);
        followEnemy->setPos(QPointF(-40,-40));
        FollowEnemyList.append(followEnemy);
    }

    for(int i=0;i<10;i++){

        bigEnemy = new BigEnemy(scene);
        bigEnemy->setPos(QPointF(-40,-40));
        BigEnemyList.append(bigEnemy);
    }
}

void TotalControl::CreateSmallEnemy(int type)//敌人产生函数,type代表敌人排布方式,顺序为顺时针,左开始
{
    if(type==0){//左敌人
        for(int i=0;i<8;i++){
            SmallEnemyList[i]->setPos(QPointF(0,i*100+50));
            SmallEnemyList[i]->setVisible(true);
            SmallEnemyList[i]->setRotation(0);
        }
        for(int i=0;i<8;i++){
            SmallEnemyList[i+8]->setPos(QPointF(1600,i*100+100));
            SmallEnemyList[i+8]->setVisible(true);
            SmallEnemyList[i+8]->setRotation(-180);
        }
    }
    if(type==1){
        for(int i=0;i<10;i++){
            SmallEnemyList[i]->setPos(QPointF(150*i+50,0));
            SmallEnemyList[i]->setRotation(90);
            SmallEnemyList[i]->setVisible(true);
        }
        for(int i=0;i<10;i++){
            SmallEnemyList[i+10]->setPos(QPointF(150*i+100,900));
            SmallEnemyList[i+10]->setRotation(-90);
            SmallEnemyList[i+10]->setVisible(true);
        }
    }
}

void TotalControl::CreateFollowEnemy(int type)
{
    if(type==0){
        for(int i=0;i<5;i++){
            FollowEnemyList[i]->setPos(QPointF(0,i*160+50));
            FollowEnemyList[i]->setVisible(true);
            FollowEnemyList[i]->setRotation(0);
        }
        for(int i=0;i<5;i++){
            FollowEnemyList[i+5]->setPos(QPointF(1600,i*150+70));
            FollowEnemyList[i+5]->setVisible(true);
            FollowEnemyList[i+5]->setRotation(-180);
        }
    }
    if(type==1){
        for(int i=0;i<5;i++){
            FollowEnemyList[i]->setPos(QPointF(i*300+50,0));
            FollowEnemyList[i]->setVisible(true);
            FollowEnemyList[i]->setRotation(90);
        }
        for(int i=0;i<5;i++){
            FollowEnemyList[i+5]->setPos(QPointF(i*300+20,900));
            FollowEnemyList[i+5]->setVisible(true);
            FollowEnemyList[i+5]->setRotation(-90);
        }
    }
}

void TotalControl::EnemyFollow(float Keyx, float Keyy)
{
    for(int i=0;i<10;i++){
        if(FollowEnemyList[i]->isVisible()){
            QLineF* temp = new QLineF(FollowEnemyList[i]->mapToScene(0,0).x(),FollowEnemyList[i]->mapToScene(0,0).y(),Keyx,Keyy);
            QLineF* temp1 = new QLineF(BigEnemyList[i]->mapToScene(0,0).x(),BigEnemyList[i]->mapToScene(0,0).y(),Keyx,Keyy);
            FollowEnemyList[i]->setRotation(-temp->angle());
            BigEnemyList[i]->setRotation(-temp1->angle());
        }
    }
}

void TotalControl::CreateBigEnemy(int type)
{
    if(type==0){
        for(int i=0;i<5;i++){
            BigEnemyList[i]->setPos(QPointF(0,i*160+50));
            BigEnemyList[i]->setVisible(true);
            BigEnemyList[i]->setStartRotate(0);
        }
        for(int i=0;i<5;i++){
            BigEnemyList[i+5]->setPos(QPointF(1600,i*150+70));
            BigEnemyList[i+5]->setVisible(true);
            BigEnemyList[i+5]->setStartRotate(-180);
        }
    }
    if(type==1){
        for(int i=0;i<5;i++){
            BigEnemyList[i]->setPos(QPointF(i*300+50,0));
            BigEnemyList[i]->setVisible(true);
            BigEnemyList[i]->setStartRotate(90);
        }
        for(int i=0;i<5;i++){
            BigEnemyList[i+5]->setPos(QPointF(i*300+20,900));
            BigEnemyList[i+5]->setVisible(true);
            BigEnemyList[i+5]->setStartRotate(-90);
        }
    }
}

